<template>
  <div>
    <!--<a-input-search @search="onSearch" style="width:100%;margin-top: 10px" placeholder="请输入目录名称"/>-->
    <!-- 树-->
    <template v-if="departTree.length>0">
      <!--组织机构-->
      <a-tree
        showLine
        :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
        :selectedKeys="selectedKeys"
        :treeData="departTree"
        :autoExpandParent="autoExpandParent"
        @select="onSelect"
        @expand="onExpand"
      />

    </template>
    <div style="margin-top: 24px;" v-else-if="departTree.length==0">
      <h3><span>暂无有效目录信息</span></h3>
    </div>
    <div style="margin-top: 24px;" v-else><h3>暂无数据</h3></div>
  </div>
</template>

<script>
  import { getAction } from '@/api/manage'

  export default {
    name: "DtgLeftTree",
    components: {

    },
    data () {
      return {
        departTree: [],
        // selectedKeys: [],
        selectedKeysNode: {},
        iExpandedKeys: [],
        loading: false,
        autoExpandParent: true,


      }
    },
    props:{
      selectedKeys: {
        type: Array,
        default(){
          return []
        }
      }
    },
    created () {
      this.refresh();

    },
    computed:{

    },
    methods:{
      loadTree() {
        let that = this
        that.departTree = []

        getAction("/base/dtgEquipmentInfo/list","").then(res=>{
          if (res.success && res.result ) {
            for (let i = 0; i < res.result.records.length; i++) {
              let temp = res.result.records[i]
              temp['title'] = temp.name;
              temp['key'] = temp.id;

              if(temp.hasChild == '1'){
                temp['children'] = [{}];
              }
              that.departTree.push(temp)
            }
            that.loading = false
          }
        })
      },

      refresh() {
        this.loading = true
        this.loadTree()
      },
      onExpand(expandedKeys) {
        this.iExpandedKeys = expandedKeys
        this.autoExpandParent = false
      },
      onSelect(selectedKeys, e) {
        // this.selectedKeys = selectedKeys;
        this.selectedKeysNode = e.node;

        this.$emit('selectNode',{selKeys:selectedKeys, keyNode: e })
      },



    }
  }
</script>

<style scoped>

</style>